package edu.pku.sei.transformation.editor.controller.commands.link;

import edu.pku.sei.transformation.editor.model.Transformation;
import edu.pku.sei.transformation.editor.model.TransformationExtend;

public class ExtendCreateCommand
		extends
		AbstractLinkCreateCommand<TransformationExtend, Transformation, Transformation> {
	public ExtendCreateCommand(TransformationExtend linkModel,
			Transformation sourceModel) {
		super(linkModel, sourceModel);
	}

	@Override
	public boolean canExecute() {
		if (source == null || target == null)
			return false;
		else
			return super.canExecute();
	}

	@Override
	public void execute() {
		source.addExtend(link);
		link.setExtendTransformation(target);
		((Transformation) source).getExtendby().add(source);
	}

	@Override
	public void undo() {
		source.getExtends().remove(link);
		link.setExtendTransformation(null);
		((Transformation) source).getExtendby().remove(source);
	}
}
